package rmi;

import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class Server01 implements IServer01{
	private Registry registry;
	public Server01(){
		this.start();
	}
	@Override
	public String answer() throws RemoteException {
		return "Hallo von Server!";
	}
	@Override
	public void start(){
        try {
			IServer01 stub = (IServer01) UnicastRemoteObject.exportObject(this, 0);
            this.registry = LocateRegistry.getRegistry();
            System.out.println(registry);
            try {
				this.registry.bind("Server01", stub);
			} catch (AlreadyBoundException e) {
				e.printStackTrace();
			}

//		} catch (RemoteException e) {
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	@Override
	public void stop(){
		
	}
	@Override
	public void shutdown(){
		this.stop();
		
		System.exit(1);
	}
}